package com.crcode.crm.service.role.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.crcode.crm.bean.role.RoleUserBean;
import com.crcode.crm.dao.role.RoleUserDao;
import com.crcode.crm.service.role.RoleUserService;
/**
 * 角色用户管理处理
 * 
 * @author lxw
 * @date 2018年9月12日 下午2:44:19
 * @version V1.0
 */
@Service(value="roleUserService")
@Transactional
public class RoleUserServiceImpl implements RoleUserService {

	@Autowired
	private RoleUserDao roleUserDao;
	
	@Override
	public RoleUserBean getById(Integer serializable) {

		return this.roleUserDao.findById(serializable).get();
	}

	@Override
	public RoleUserBean saveResultBean(RoleUserBean t) {

		return this.roleUserDao.save(t);
	}

	@Override
	public boolean saveResultBoolean(RoleUserBean t) {
		try {
			this.roleUserDao.save(t);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	@Override
	public boolean beathSaveResultBoolean(List<RoleUserBean> t) {
		try {
			this.roleUserDao.saveAll(t);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public RoleUserBean updateResultBean(RoleUserBean t) {

		return this.roleUserDao.save(t);
	}

	@Override
	public boolean updateResultBoolean(RoleUserBean t) {
		try {
			this.roleUserDao.save(t);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public boolean delete(Integer serializable) {
		try {
			this.roleUserDao.deleteById(serializable);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public List<RoleUserBean> getAll() {

		return this.roleUserDao.findAll();
	}

	@Override
	public boolean deleteByRoleId(String roleUuid) {
		try {
			this.roleUserDao.deleteByRoleUuid(roleUuid);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public boolean deleteByRoleUuidIn(List<String> roleUuids) {
		
		try {
			this.roleUserDao.deleteByRoleUuidIn(roleUuids);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public boolean deleteByUserUuid(String userUuid) {
		try {
			this.roleUserDao.deleteByUserUuid(userUuid);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public boolean deleteByUserUuidIn(List<String> userUuids) {
		try {
			this.roleUserDao.deleteByUserUuidIn(userUuids);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public List<String> getRoleUuidsByUserUuid(String userUuid) {
	
		return this.roleUserDao.getRoleUuidsByUserUuid(userUuid);
	}

	@Override
	public List<String> getUserIdsByRoleId(String roleUuid) {

		return this.roleUserDao.getUserUuidsByRoleUuid(roleUuid);
	}

	@Override
	public boolean deleteEntitys(List<RoleUserBean> rus) {
		try {
			this.roleUserDao.deleteAll(rus);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public List<RoleUserBean> findByRoleUuidAndUserUuid(String roleUuid, String userUuid) {

		return this.roleUserDao.findByRoleUuidAndUserUuid(roleUuid, userUuid);
	}


}
